/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * FramePrincipal.java
 *
 * Created on 12/11/2010, 15:05:12
 */

package all_pet_iv.gui;

import all_pet_iv.business.Fachada;
import java.awt.Image;
import java.awt.Toolkit;
import java.net.URL;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import com.mysql.jdbc.exceptions.jdbc4.CommunicationsException;

/**
 *
 * @author Daniel
 */
public class FramePrincipal extends javax.swing.JFrame {

    private static FramePrincipal instance;
    public Fachada fachada;

    public static FramePrincipal getInstance(){
        if(instance==null){
            instance = new FramePrincipal();
        }
        return instance;
    }

     
    /** Creates new form FramePrincipal */
    private FramePrincipal() {
        initComponents();
        URL url = this.getClass().getResource("/all_pet_iv/gui/icons/patinha_grande.png");
        Image icon = Toolkit.getDefaultToolkit().getImage(url);
        this.setIconImage(icon);
        try{
            this.fachada = new Fachada();
        }catch (CommunicationsException e){
            JOptionPane.showMessageDialog(null, "Não foi possível conectar"+
                    " com o banco de dados. Confira se o serviço "+
                    "do MySQL está habilitado!", "Erro", JOptionPane.ERROR_MESSAGE);
            System.exit(0);
        } catch(SQLException ex){
            Logger.getLogger(FramePrincipal.class.getName()).log(Level.SEVERE,null,ex);
        }
    }
    
     /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jMenuBar = new javax.swing.JMenuBar();
        jMenuArquivo = new javax.swing.JMenu();
        jMenuArquivoHome = new javax.swing.JMenuItem();
        jMenuArquivoSair = new javax.swing.JMenuItem();
        jMenuFornecedor = new javax.swing.JMenu();
        jMenuComprarFornecedor = new javax.swing.JMenuItem();
        jMenuRelatorios = new javax.swing.JMenu();
        jMenuRelatoriosEstoque = new javax.swing.JMenuItem();
        jMenuVendas = new javax.swing.JMenu();
        jMenuItemVendasCaixa = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        setTitle("ALLPET - Seu software de gerenciamento de PetShops!");
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });

        jMenuArquivo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/all_pet_iv/gui/icons/file-manager.png"))); // NOI18N
        jMenuArquivo.setText("Arquivo");

        jMenuArquivoHome.setIcon(new javax.swing.ImageIcon(getClass().getResource("/all_pet_iv/gui/icons/House.png"))); // NOI18N
        jMenuArquivoHome.setText("Home");
        jMenuArquivoHome.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuArquivoHomeActionPerformed(evt);
            }
        });
        jMenuArquivo.add(jMenuArquivoHome);

        jMenuArquivoSair.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F4, java.awt.event.InputEvent.ALT_MASK));
        jMenuArquivoSair.setIcon(new javax.swing.ImageIcon(getClass().getResource("/all_pet_iv/gui/icons/Sign In.png"))); // NOI18N
        jMenuArquivoSair.setText("Sair");
        jMenuArquivoSair.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuArquivoSairActionPerformed(evt);
            }
        });
        jMenuArquivo.add(jMenuArquivoSair);

        jMenuBar.add(jMenuArquivo);

        jMenuFornecedor.setIcon(new javax.swing.ImageIcon(getClass().getResource("/all_pet_iv/gui/icons/kdmconfig.png"))); // NOI18N
        jMenuFornecedor.setText("Fornecedor");
        jMenuFornecedor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuFornecedorActionPerformed(evt);
            }
        });

        jMenuComprarFornecedor.setIcon(new javax.swing.ImageIcon(getClass().getResource("/all_pet_iv/gui/icons/Shopping-Cart-World-32.png"))); // NOI18N
        jMenuComprarFornecedor.setText("Comprar");
        jMenuComprarFornecedor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuComprarFornecedorActionPerformed(evt);
            }
        });
        jMenuFornecedor.add(jMenuComprarFornecedor);

        jMenuBar.add(jMenuFornecedor);

        jMenuRelatorios.setIcon(new javax.swing.ImageIcon(getClass().getResource("/all_pet_iv/gui/icons/kate.png"))); // NOI18N
        jMenuRelatorios.setText("Relatórios");
        jMenuRelatorios.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuRelatoriosActionPerformed(evt);
            }
        });

        jMenuRelatoriosEstoque.setIcon(new javax.swing.ImageIcon(getClass().getResource("/all_pet_iv/gui/icons/ark_addfile.png"))); // NOI18N
        jMenuRelatoriosEstoque.setText("Estoque");
        jMenuRelatoriosEstoque.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuRelatoriosEstoqueActionPerformed(evt);
            }
        });
        jMenuRelatorios.add(jMenuRelatoriosEstoque);

        jMenuBar.add(jMenuRelatorios);

        jMenuVendas.setIcon(new javax.swing.ImageIcon(getClass().getResource("/all_pet_iv/gui/icons/Shopping cart_ico.png"))); // NOI18N
        jMenuVendas.setText("Vendas");

        jMenuItemVendasCaixa.setIcon(new javax.swing.ImageIcon(getClass().getResource("/all_pet_iv/gui/icons/cifrao.png"))); // NOI18N
        jMenuItemVendasCaixa.setText("Caixa");
        jMenuItemVendasCaixa.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItemVendasCaixaActionPerformed(evt);
            }
        });
        jMenuVendas.add(jMenuItemVendasCaixa);

        jMenuBar.add(jMenuVendas);

        setJMenuBar(jMenuBar);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 492, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 267, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jMenuRelatoriosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuRelatoriosActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jMenuRelatoriosActionPerformed

    private void jMenuRelatoriosEstoqueActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuRelatoriosEstoqueActionPerformed
        FramePrincipal.getInstance().setContentPane(new PanelEstoque());
        FramePrincipal.getInstance().setVisible(true);
    }//GEN-LAST:event_jMenuRelatoriosEstoqueActionPerformed

    private void jMenuArquivoHomeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuArquivoHomeActionPerformed
        FramePrincipal.getInstance().setContentPane(new PanelHome());
        FramePrincipal.getInstance().setVisible(true);
    }//GEN-LAST:event_jMenuArquivoHomeActionPerformed

    private void jMenuArquivoSairActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuArquivoSairActionPerformed
        formWindowClosing(null);
    }//GEN-LAST:event_jMenuArquivoSairActionPerformed

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
        Object[] opcoes = { "Sim", "Não" };
        int retorno = JOptionPane.showOptionDialog(null,
        "Deseja encerrar a aplicação?","Saindo da Aplicação",JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE,null, opcoes, opcoes[0]);
         if (retorno == 0){
               // JOptionPane.showMessageDialog(null, "Obrigado por confiar no ALLPET!", "Volte sempre", JOptionPane.INFORMATION_MESSAGE);
                System.exit(0);
            }
 
    }//GEN-LAST:event_formWindowClosing

    private void jMenuItemVendasCaixaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemVendasCaixaActionPerformed
        FramePrincipal.getInstance().setContentPane(new PanelCaixa());
        FramePrincipal.getInstance().setVisible(true);
    }//GEN-LAST:event_jMenuItemVendasCaixaActionPerformed

    private void jMenuFornecedorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuFornecedorActionPerformed
       // 
    }//GEN-LAST:event_jMenuFornecedorActionPerformed

    private void jMenuComprarFornecedorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuComprarFornecedorActionPerformed
        FramePrincipal.getInstance().setContentPane(new PanelComprarFornecedor());
        FramePrincipal.getInstance().setVisible(true);
        
    }//GEN-LAST:event_jMenuComprarFornecedorActionPerformed

       /**
    * @param args the command line arguments
    */


    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                FramePrincipal.getInstance().setExtendedState(MAXIMIZED_BOTH);
                FramePrincipal.getInstance().setContentPane(new PanelHome());
                FramePrincipal.getInstance().setVisible(true);
            }
        });

    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenu jMenuArquivo;
    private javax.swing.JMenuItem jMenuArquivoHome;
    private javax.swing.JMenuItem jMenuArquivoSair;
    private javax.swing.JMenuBar jMenuBar;
    private javax.swing.JMenuItem jMenuComprarFornecedor;
    private javax.swing.JMenu jMenuFornecedor;
    private javax.swing.JMenuItem jMenuItemVendasCaixa;
    private javax.swing.JMenu jMenuRelatorios;
    private javax.swing.JMenuItem jMenuRelatoriosEstoque;
    private javax.swing.JMenu jMenuVendas;
    // End of variables declaration//GEN-END:variables

}
